DEFINE VARIABLE qty_avg AS DECIMAL.
DEFINE VARIABLE n AS DECIMAL.
DEFINE VARIABLE stdev AS DECIMAL.
DEFINE BUFFER trhist FOR tr_hist.

FOR EACH tr_hist WHERE tr_hist.tr_type = 'iss-wo' BREAK BY tr_hist.tr_part: 

    FOR EACH trhist 
        WHERE trhist.tr_type = 'iss-wo' AND trhist.tr_part = tr_hist.tr_part
        BREAK BY trhist.tr_part:
      ACCUMULATE trhist.tr_qty_chg (AVERAGE BY trhist.tr_part).
      ACCUMULATE trhist.tr_qty_chg (COUNT BY trhist.tr_part).
    END.

    ASSIGN qty_avg = ACCUM AVERAGE trhist.tr_qty_chg.
    ASSIGN n = ACCUM COUNT trhist.tr_qty_chg.
    
    FOR EACH trhist 
        WHERE trhist.tr_type = 'iss-wo' AND trhist.tr_part = tr_hist.tr_part
        BREAK BY trhist.tr_part:
      ACCUMULATE exp(trhist.tr_qty_chg - qty_avg, 2) (TOTAL BY tr_part). 
    END.
    
    ASSIGN stdev = ACCUM SUB-TOTAL exp(trhist.tr_qty_chg - qty_avg, 2).
    IF n > 1 THEN
       ASSIGN stdev = exp(stdev / (n - 1), 0.5).
    ELSE 
       ASSIGN stdev = ?.

    DISP tr_hist.tr_part 
         tr_hist.tr_qty_chg
         n                  LABEL "N"
         qty_avg            LABEL "AVG"
         stdev              LABEL "STDEV"
        .

END.
